package com.stenio.fancat.controller.baby;

import com.stenio.fancat.controller.Result;
import com.stenio.fancat.domain.baby.FcBehaviorImage;
import com.stenio.fancat.service.OssService;
import com.stenio.fancat.service.baby.BehaviorImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @author liuan
 * @create 2019-01-16 20:27
 */
@RestController
@RequestMapping("task/image")
public class BehaviorImageController {

    @Autowired
    private BehaviorImageService behaviorImageService;

    /**
     * 上传图片
     * @param multipartFile
     * @return
     */
    @PostMapping("upload")
    @ResponseBody
    public Result<FcBehaviorImage> upload(@RequestParam(name = "file") MultipartFile multipartFile){
        Result<FcBehaviorImage> result = new Result();
        result.setData(behaviorImageService.saveImage(multipartFile));
        return result;
    }

    @GetMapping("{bId}")
    @ResponseBody
    public Result<List<FcBehaviorImage>> selectByType(@PathVariable String bId){
        Result<List<FcBehaviorImage>> result = new Result();
        FcBehaviorImage behaviorImage = new FcBehaviorImage();
        behaviorImage.setBehaviorId(bId);
        result.setData(behaviorImageService.selectByType(behaviorImage));
        return result;
    }


}

